/**
 * Created by Francis.LW on 2017/10/20.
 *
 * 权限服务接口
 */
import {postRequest, getRequest} from '@/common/request'
import {urls} from './url'

const permissionApi = urls.permission

function listAllPermission(param, success, complete) {
  postRequest(permissionApi.listAllPermission, {}, param, success, complete)
}

/**
 * 获取角色没有的权限列表
 * @param param
 * @param page
 * @param pageSize
 * @param success
 * @param complete
 */
function listPermissionNotSelectd(rid, param, page, pageSize, success, complete) {
  postRequest(permissionApi.listPermissionNoSelectd + rid + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}

/**
 * 获取角色已有的权限列表
 * @param param
 * @param page
 * @param pageSize
 * @param success
 * @param complete
 */
function listPermissionSelectd(rid, param, page, pageSize, success, complete) {
  postRequest(permissionApi.listPermissionSelectd + rid + '?currentpage=' + page + '&pagesize=' + pageSize, {}, param, success, complete)
}

/**
 * 创建新权限
 * @param param
 * @param success
 * @param complete
 */
function addPermission(param, success, complete) {
  postRequest(permissionApi.savePermission, {}, param, success, complete)
}


/**
 * 删除权限信息
 * @param ids
 * @param success
 * @param complete
 */
function deletePermission(ids, success, complete) {
  postRequest(permissionApi.removePermission, {}, ids, success, complete)
}

/**
 *
 * @param ids
 * @param success
 * @param complete
 */
function deleteSinglePermission(id, success, complete) {
  let ids = []
  ids.push(id)
  deletePermission(ids, success, complete)
}

function reloadPermission(success, complete) {
  postRequest(permissionApi.reloadPermission, {}, {}, success, complete)
}

export default {
  listAllPermission,
  listPermissionNotSelectd,
  listPermissionSelectd,
  addPermission,
  deletePermission,
  deleteSinglePermission,
  reloadPermission
}
